package sat.component;

import java.util.Arrays;
import java.util.List;

import org.mt4j.MTApplication;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.font.IFont;
import org.mt4j.components.visibleComponents.shapes.MTPolygon;
import org.mt4j.components.visibleComponents.widgets.MTTextField;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;
import org.mt4jx.components.visibleComponents.widgets.MTSuggestionTextArea;

import sat.model.LinkModel;

public class Link {
	private static final float widthPreferred = 150;
	private static final float heightPreferred = 20;
	private static final int fontsize = 15;
	
	private LinkModel model;
	private KeyboardTextField title;
	private MTTextField card1;
	private MTTextField card2;
	private LinkAssociation linkLine;
	
	private MTSuggestionTextArea sugBox;
	
	public KeyboardTextField getTitle() {
		return title;
	}

	public void setTitle(KeyboardTextField title) {
		this.title = title;
	}

	public MTTextField getCard1() {
		return card1;
	}

	public void setCard1(MTTextField card1) {
		this.card1 = card1;
	}

	public MTTextField getCard2() {
		return card2;
	}

	public void setCard2(MTTextField card2) {
		this.card2 = card2;
	}

	 
	
	public enum LinkType{ASSOCIATION, AGREGATION, COMPOSITION, HERITAGE};
	
	public Link(MTApplication mtApplication, MTPolygon ent1, MTPolygon ent2){
		System.out.println("creation link");
		model = new LinkModel(this, null, null, null);
		linkLine = new LinkAssociation(mtApplication, ent1, ent2);
		IFont textFont = FontManager.getInstance().createFont(mtApplication, "Arial",//"Comic Sans MS",
				fontsize, // Font size
				new MTColor(56, 62, 52, 255), // Font fill color
				true);
		
		title = new KeyboardTextField(mtApplication, widthPreferred, heightPreferred, KeyboardTextField.type.links, null, null);
		title.setText("Name Link");
		title.setFillColor(new MTColor(0, 0, 0, 0));
		title.setStrokeColor(new MTColor(125, 125,125, 0));
		title.setPositionGlobal(new Vector3D(linkLine.getCenterPointGlobal().getX()+20, linkLine.getCenterPointGlobal().getY()-20, 0));
		linkLine.addChild(title);
		/*
		String[] su=new String[] {"0","1","*","1..*"};
		List<String> suggestion = Arrays.asList(su);  
		sugBox = new MTSuggestionTextArea(mtApplication, widthPreferred/2, suggestion);
		sugBox.setFillColor(new MTColor(0, 0, 0, 255));
		sugBox.setStrokeColor(new MTColor(0, 0, 0, 255));
		sugBox.setPositionRelativeToParent(new Vector3D(-widthPreferred/2, heightPreferred/2));
		title.addChild(sugBox);*/

		card1 = new MTTextField(mtApplication, 0, 0, 40, heightPreferred, textFont);
		card1.setFillColor(new MTColor(0, 0, 0, 0));
		card1.setStrokeColor(new MTColor(56, 62, 52, 0));
		card1.setPositionRelativeToParent(new Vector3D(-20, heightPreferred/2));
		card1.setText("1");
		title.addChild(card1);
		 
//		card1.setText("1");

		card2 = new MTTextField(mtApplication, 0, 0, 40, heightPreferred, textFont);
		card2.setFillColor(new MTColor(0, 0, 0, 0));
		card2.setStrokeColor(new MTColor(56, 62, 52, 0));
		card2.setPositionRelativeToParent(new Vector3D(widthPreferred+20, heightPreferred/2));
		card2.setText("1 .. *");
		title.addChild(card2);
	}
	
	public void setTypeLink(final LinkType linkType){
		switch (linkType) 
		{
		case ASSOCIATION :
			System.out.println("creation Association");
			break;
		}
	}

	public LinkAssociation getLinkLine() {
		return linkLine;
	}

	public void setLinkLine(LinkAssociation linkLine) {
		this.linkLine = linkLine;
	}

//	public MTPolygon getEntity1(){
//		return model.getEntity1();
//	}
//	
//	public void setEntity1(MTPolygon ent1){
//		model.setEntity1(ent1);
//	}
//	
//	public MTPolygon getEntity2(){
//		return model.getEntity2();
//	}
//	
//	public void setEntity2(MTPolygon ent2){
//		model.setEntity2(ent2);
//	}
//	
//	public Vertex getEntity1Centre(){
//		return linkLine.getEntity1Centre();
//	}
//	
//	public Vertex getEntity2Centre(){
//		return linkLine.getEntity2Centre();
//	}
}
